package test_achieve;

import com.sun.org.apache.xpath.internal.SourceTree;
import constant.Constant;
import constant.Pm;
import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import org.junit.Assert;
import test_achieve.courierapp.HttpCourier;
import util.ConfigSql;
import util.JdbcUtil;
import util.tools.BusinessTools;
import util.tools.CommonTools;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by chenkuo on 2017/7/3.
 */
public class Feature1 {

    @Given("^这是一个feature：(.*)$")
    public void 这是一个feature(String name) throws Throwable {
//        JdbcUtil sql = new JdbcUtil();
//        int deliveryPassword = sql.sqlInt("SELECT delivery_password FROM order2.infos WHERE order_number='TDH2017081116200076'");
//        int OrderStatus = sql.sqlInt("SELECT `status` FROM order2.orders WHERE order_number='TDH2017080410202242'");
        BusinessTools.removeLoginNum("15501213529","pc_USER");

        System.out.println(name);
//        Assert.assertEquals(true,false);
        //    HttpClient httpClient = new HttpClient();
//        InetAddress localhost = InetAddress.getLocalHost();
//        System.out.println(localhost.getHostAddress());


//抢单页面稳定性支持：
        //        int width = Constant.driverCourier.manage().window().getSize().width;//手机屏宽
//        int height = Constant.driverCourier.manage().window().getSize().height;//手机屏高
//        Constant.driverCourier.swipe(width * 1 / 2, height / 2, width * 1 / 2, height / 8, 200);
//        Constant.driverCourier.swipe(width * 1 / 2, height / 2, width * 1 / 2, height / 8, 200);
//        /*点击宽度（左面）二分之一，高度处2分之一处，滑动到上方八分之一处*/
//        String order = Constant.driverCourier.findElement(By.id("tasknumber_txt")).getText().substring(3, 22);
//        System.out.println(order);
//        if (!(Constant.OrderNumbuter.get(Constant.OrderNumbuter.size()-1).equals(order))) {//判断当前页面订单
//            Constant.driverCourier.findElement(By.id("close")).click();//关闭抢单页面
//            Thread.sleep(4000);//预留推单时间
//            Constant.driverCourier.findElement(By.id("btn_wait_grab")).click();//进入待抢单
//            Thread.sleep(3000);//订单加载
//            Constant.driverCourier.findElement(By.name(Constant.OrderNumbuter.get(Constant.OrderNumbuter.size()-1)));
//            Thread.sleep(1000);
//        }



    }

    @Given("^这是另外个feature$")
    public void 这是另外个feature() throws Throwable {
        System.out.println("这是另外一个feature");
    }

    @Given("^参数传递测试"+Pm.p3)
    public void  参数传递(String arg0,String arg1,String arg2) throws Throwable {
        System.out.println("这里面有3个参数"+arg0);
    }


    @Given("^参数传递测试"+Pm.p2)
    public void  参数传递(String arg0, String arg1) throws Throwable {
        System.out.println("这里面有2个参数"+arg0+arg1);
    }

    @Given("^我是第一条feature$")
    public void 我是第一条feature() throws Throwable {
        System.out.println("我是第一条feature");
    }
    @Given("^我是一条会报错的feature$")
    public void 我是一条会报错的feature() throws Throwable {
        System.out.println("我是第一条会报错的feature");
        throw new RuntimeException("ddd");
    }

    @Given("^我是另外一条feature：(.*)$")
    public void 我是另外一条feature(String pra) throws Throwable {
        System.out.println("我是另外一条feature"+pra);
    }

    @Given("^数据库测试$")
    public void 数据库测试() throws Throwable {
        Map<String, String> envs = System.getenv();
        for(String key : envs.keySet()) {
            System.out.println(key + "=" + envs.get(key));
        }
        int a = JdbcUtil.sqlInt(ConfigSql.get("queryorder2status","TDH2018022712384612"));
        System.out.println(a);
        String visit_name = "场景名称";
        String machine_ip = "100.125.123.31";
        int result = 1;
        int status = 1;
        Date now = new Date();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowstr = df.format(now);
//        CommonTools.getDateUnixTime(0);
        String html_report = "http://172.33.0.5:8081/jenkins/view/autotest/job/"+envs.get("JOB_NAME")+"/"+envs.get("BUILD_ID")+"/cucumber-html-reports/overview-features.html";
        String create_time = "";//插入时间
        String operator = "阿强";
        String id = "";//自增
        String sql = "insert itest.u_simple_result(visit_name,machine_ip,result,status," +
                "html_report,create_time,operator) values ('"+visit_name+"','"+machine_ip+"',"
                +result+","+status+",'"+html_report+"','"+nowstr+"','"+operator+"')";
        JdbcUtil.sqlReportExecute(sql);

    }

    @Given("^添加订单号：(.*)$")
    public void 添加订单号订单号(String orderNum) throws Throwable {
        Constant.OrderNumbuter.add(orderNum);
    }

    @Given("^参数验证：(.*)$")
    public void 参数验证(String abc) throws Throwable {
        System.out.println("---------------:"+abc);
    }

    @Given("^对手机号进行脱敏：(.*)$")
    public void 对手机号进行脱敏(String number) throws Throwable {
        BusinessTools.getMobileSecret(number);
    }

    @Given("^获取闪送员的tonken：(.*)$")
    public void 获取闪送员的tonken(String num) throws Throwable {
        String userSecret = BusinessTools.getMobileSecret(num);
        HttpCourier.gettoken(userSecret);
    }

    /**         ^       匹配输入字符串的开始位置
     *          $       匹配输入字符串的结束位置
     *
     *         ( )      将( 和 ) 之间的表达式定义为“组”（group），并且将匹配这个表达式的字符保存到一个临时区域（一个正则表达式中最多可以保存9个），它们可以用 \1 到\9 的符号来引用。
     *          匹配输入字符串的结束位置
     */

}
